<%# Redmine plugin for Document Management System "Features"
#
# Copyright (C) 2011    Vít Jonáš <vit.jonas@gmail.com>
# Copyright (C) 2012    Daniel Munn <dan.munn@munnster.co.uk>
# Copyright (C) 2011-14 Karel Picman <karel.picman@kontron.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.%>

<p>
  <%= content_tag(:label, "#{l(:label_maximum_files_upload)}:") %>
  <%= text_field_tag 'settings[dmsf_max_file_upload]', @settings['dmsf_max_file_upload'], :size => 10 %><br/>
  (<%= l(:label_default) %>: 0)
  <br/>
  <%= l(:note_maximum_number_of_files_uploaded) %>
</p>

<p>
  <%= content_tag(:label, "#{l(:label_maximum_files_download)}:") %>
  <%= text_field_tag 'settings[dmsf_max_file_download]', @settings['dmsf_max_file_download'], :size => 10 %><br/>
  (<%= l(:label_default) %>: 0)
  <br/>
  <%= l(:note_maximum_number_of_files_downloaded) %>
</p>

<p>
  <%= content_tag(:label, "#{l(:label_maximum_email_filesize)}:") %>
  <%= text_field_tag 'settings[dmsf_max_email_filesize]', @settings['dmsf_max_email_filesize'], :size => 10 %><br/>
  (<%= l(:label_default) %>: 0)
  <br/>
  <%= l(:note_maximum_email_filesize) %>
</p>

<p>
  <%= content_tag(:label, "#{l(:label_maximum_ajax_upload_filesize)}:") %>  
  <%= text_field_tag 'settings[dmsf_max_ajax_upload_filesize]', @settings['dmsf_max_ajax_upload_filesize'], :size => 10 %><br/>
  (<%= l(:label_default) %>: 100)
  <br/>
  <%= l(:note_maximum_ajax_upload_filesize) %>
</p>

<p>
  <%=  content_tag(:label, "#{l(:label_file_storage_directory)}:") %>
  <% 
    storage_dir = @settings['dmsf_storage_directory'].strip
    storage_dir = "#{Rails.root}/files/dmsf" if storage_dir.blank?
  %>
  <%= text_field_tag 'settings[dmsf_storage_directory]', storage_dir, :size => 50 %><br/>
  (<%= l(:label_default) %>: <%= "#{Rails.root}/files/dmsf" %>)
</p>
<% unless File.exists?(storage_dir) %>
  <% begin %>
     <% Dir.mkdir(storage_dir) %>
  <% rescue %>
    <p class="warning"><%= l(:error_file_storage_directory_does_not_exist) %></p> 
  <% end %>
<% end %>
<% testfilename = "#{storage_dir}/test.test" %>
<% if File.exists?(storage_dir) %>
  <%	begin %>
    <% File.open(testfilename, 'wb') do |file| %>
    <% end %>
  <% rescue %>
    <p class="warning"><%= l(:error_file_can_not_be_created) %></p>
  <%	ensure %>
    <% File.delete(testfilename) if File.exists?(testfilename) %>
  <% end %>
<% end %>

<p>
  <%= content_tag(:label, "#{l(:label_physical_file_delete)}:") %>
  <%= check_box_tag('settings[dmsf_really_delete_files]', true, @settings['dmsf_really_delete_files']) %><br/>
  (<%=l(:label_default)%>: <%=l(:general_text_No)%>)
</p>

<p>
  <%= content_tag(:label, "#{l(:label_default_notifications)}:") %>
  <%= select_tag('settings[dmsf_default_notifications]', 
    options_for_select([
                    [l(:select_option_deactivated), nil], 
                    [l(:select_option_activated), '1']], 
                    :selected => @settings['dmsf_default_notifications'])) %><br/>
  (<%= l(:label_default) %>: <%= l(:select_option_deactivated) %>)
</p>

<p>
  <%= content_tag(:label, "#{l(:label_display_notified_recipients)}:") %>
  <%= select_tag('settings[dmsf_display_notified_recipients]',
    options_for_select([
      [l(:select_option_deactivated), nil],
      [l(:select_option_activated), '1']],
      :selected => @settings['dmsf_display_notified_recipients'])) %><br/>
  (<%= l(:label_default) %>: <%= l(:select_option_deactivated) %>)
  <br/>
  <%= l(:note_display_notified_recipients).html_safe %>
</p>

<hr />

<p>
  <%= content_tag(:label, "#{l(:label_webdav)}:") %>
  <%= select_tag('settings[dmsf_webdav]',
    options_for_select([
      [l(:select_option_deactivated), nil],
      [l(:select_option_activated), '1']],
      :selected => @settings['dmsf_webdav'])) %><br/>
  (<%= l(:label_default) %>: <%= l(:select_option_activated) %>)
  <br/>
  <%= l(:note_webdav).html_safe %>
</p>

<% if @settings['dmsf_webdav'].nil? || !@settings['dmsf_webdav'].empty? %>
  <p>
    <%= content_tag(:label, "#{l(:label_webdav_strategy)}:") %>
    <%= select_tag('settings[dmsf_webdav_strategy]',
      options_for_select([
        [l(:select_option_webdav_readonly), 'WEBDAV_READ_ONLY'],
        [l(:select_option_webdav_readwrite), 'WEBDAV_READ_WRITE']],
        :selected => @settings['dmsf_webdav_strategy'])) %><br/>
    (<%= l(:label_default) %>: <%= l(:select_option_webdav_readonly) %>)
    <br/>
    <%= l(:note_webdav_strategy).html_safe %>
  </p>
<% end %>

<hr />

<% begin %>
  <% require 'xapian' %>
  <% xapian_disabled = false %>
<% rescue LoadError %>
  <p class="warning"><%= l(:warning_xapian_not_available) %></p> 
  <% xapian_disabled = true %>
<% end %>

<p>
  <%= content_tag(:label, "#{l(:label_index_database)}:") %>
  <%= text_field_tag 'settings[dmsf_index_database]', @settings['dmsf_index_database'], :disabled => xapian_disabled, :size => 50 %><br/>
  (<%= l(:label_default) %>: <%= "#{Rails.root}/files/dmsf_index" %>)
</p>

<p>
  <%= content_tag(:label, "#{l(:label_stemming_language)}:") %>
  <%= text_field_tag 'settings[dmsf_stemming_lang]', @settings['dmsf_stemming_lang'], :disabled => xapian_disabled %><br/>
  (<%= l(:label_default)%>: english )<br/>
  <br/>
  <%= l(:note_possible_values)%>: danish dutch english finnish french german german2 hungarian italian kraaij_pohlmann lovins norwegian porter portuguese romanian russian spanish swedish turkish (<%= l(:note_pass_none_to_disable_stemming) %>)</p>

<p>
  <%= content_tag(:label, l(:label_stem_strategy) + ":")%>
  <%= radio_button_tag 'settings[dmsf_stemming_strategy]', 'STEM_NONE', @settings['dmsf_stemming_strategy'] == 'STEM_NONE', :disabled => xapian_disabled, :checked=>true  %> <%= l(:option_stem_none) %><br>
  <%= radio_button_tag 'settings[dmsf_stemming_strategy]', 'STEM_SOME', @settings['dmsf_stemming_strategy'] == 'STEM_SOME', :disabled => xapian_disabled  %> <%= l(:option_stem_some) %><br>
  <%= radio_button_tag 'settings[dmsf_stemming_strategy]', 'STEM_ALL', @settings['dmsf_stemming_strategy'] == 'STEM_ALL', :disabled => xapian_disabled  %> <%= l(:option_stem_all) %><br>
  <br/>
  <%= l(:label_stemming_description) %>:
  <br>
    STEM_NONE: <%=l(:note_do_not_stem) %><br>
    STEM_SOME: <%=l(:note_stem_some) %><br>
    STEM_ALL: <%=l(:note_stem_all) %><br>
  <br/>
  <%= l(:note_stemming_applied) %><br>
</p>
